package com.example.xianji.activity;

import org.json.JSONException;
import org.json.JSONObject;

import com.example.xianji.Contant;
import com.example.xianji.R;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.os.Bundle;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.RelativeLayout;

public class Main_DuiJie_XieYiActivity extends Activity {
    private WebView xieyi_webview;
    private RelativeLayout duijie_xieyi_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_main__dui_jie__xie_yi);
        xieyi_webview = (WebView) findViewById(R.id.xieyi_webview);
        duijie_xieyi_back = (RelativeLayout) findViewById(R.id.duijie_xieyi_back);
        duijie_xieyi_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Main_DuiJie_XieYiActivity.this.finish();
            }
        });
        duijie();
    }

    public void duijie() {
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();
        parms.addBodyParameter("id", 14 + "");
        httpUtils.send(HttpMethod.POST, Contant.xieyi, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject object = new JSONObject(arg0.result);
                            if (object.getInt("status") == 1) {
                                xieyi_webview.loadDataWithBaseURL(null, object.getJSONObject("data").getString("details"), "text/html", "utf-8", null);
                            }
                        } catch (JSONException e1) {
                            e1.printStackTrace();
                        }
                    }
                });
    }
}
